#pragma once

#include <map>
#include <memory>
#include <string>
#include <vector>

#include <gl/glew.h>
#define GLFW_DLL
#include <gl/glfw.h>

#include "primitives/graph.h"

#include "renderer/subrenderer.h"

class River;
class Road;

class TerrainRenderer:public SubRenderer{
    public:
        TerrainRenderer(int width, int height, float frustumScale, float zNear, float zFar);
        void LoadTerrain();
        void Draw();
        void Pick();

    private:
        void LoadTerrainTextures(std::vector<std::string> textureFileLocs);
        void LoadTerrainMesh();

        void LoadTerritoryEdges();
        void LoadRivers();
        void LoadRiverTextures();
        void BuildRiverMesh(Graph rivers);
        int BuildNationEdgeMesh(std::vector<float> & verts, std::vector<float> & uvs);
        void AddEdge(std::vector<float> & verts, std::vector<float> & uvs, int x, int y, int rot);

        void LoadRoads();
        int BuildPathMesh(Graph roads, std::vector<float> & verts, std::vector<float> & uvs);
        void CreateVAO(GLuint & vao, std::vector<float> & verts, std::vector<float> & uvs);
        void LoadRoadTextures();

        GLuint terrainDrawVAO;
        GLuint river_vao;
        GLuint road_vao;
        GLuint territory_edge_vao;
        GLuint pick_vao;

        unsigned int num_river_segments;
        unsigned int num_road_segments;
        unsigned int num_edge_triangles;

        GLuint superTexture;
        GLuint roadTexture;
        std::map<std::string,int> textureIndices;
};

